package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.hr.constant.EmpSocStatus;
import org.jsola.hr.vo.excel.FieldItemVO;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import static org.jsola.hr.example.EmpInfoExample.E_CHANNEL_ID;
import static org.jsola.hr.example.EmpInfoExample.N_CHANNEL_ID;
import static org.jsola.hr.example.EmpSocInfoExample.*;

/**
 * 员工参保信息表
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class EmpSocInfoQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = "标签list")
    private List<String> tagList;

    @ApiParam(value = N_SUPPLEMENT_TYPE, example = E_SUPPLEMENT_TYPE)
    @Length(max = 4)
    private String supplementType;

    @ApiParam(value = N_EMP_ID, example = E_EMP_ID)
    @Length(max = 32)
    private String empId;

    @ApiParam(value = N_PROG_ID, example = E_PROG_ID)
    @Length(max = 32)
    private String progId;

    @ApiParam(value = N_MONTH_ID, example = E_MONTH_ID)
    @Length(max = 32)
    private String monthId;

    @ApiParam(value = N_YEAR, example = E_YEAR)
    @Length(max = 32)
    private String year;

    @ApiParam(value = N_MONTH, example = E_MONTH)
    @Length(max = 32)
    private String month;

    @ApiParam(value = N_PERSONAL_SOC_AMOUNT, example = E_PERSONAL_SOC_AMOUNT)
    private BigDecimal personalSocAmount;

    @ApiParam(value = N_PERSONAL_PF_AMOUNT, example = E_PERSONAL_PF_AMOUNT)
    private BigDecimal personalPfAmount;

    @ApiParam(value = N_COMPANY_SOC_AMOUNT, example = E_COMPANY_SOC_AMOUNT)
    private BigDecimal companySocAmount;

    @ApiParam(value = N_COMPANY_PF_AMOUNT, example = E_COMPANY_PF_AMOUNT)
    private BigDecimal companyPfAmount;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = N_NAME, example = E_NAME)
    private String name;

    @ApiParam(value = N_SOC_CITY, example = E_SOC_CITY)
    private String socCity;

    @ApiParam(value = N_GROUP_ID, example = E_GROUP_ID)
    @Length(max = 50)
    private String groupId;

    @ApiParam(value = "社保状态")
    private Integer empSocStatus;

    @ApiParam(value = "医保状态")
    private Integer empMeStatus;

    @ApiParam(value = "公积金状态")
    private Integer empPfStatus;

    @ApiParam(value = "参保管理顶部状态筛选")
    private Integer topStatus;

    @ApiParam(value = N_DEP_ID, example = E_DEP_ID)
    private String depId;

    @ApiParam(value = N_ID, example = E_ID)
    private String id;

    @ApiParam(value = "缴费类型")
    private Integer socPayCostType;

    @ApiParam(value = "参保方案Id")
    private String socProgId;

    @ApiParam(value = "员工状态")
    private Integer status;

    @ApiParam(value = "员工类型")
    private Integer postType;

    @ApiParam(value = "渠道ID")
    private String channelId;

    @ApiParam(value = "标签")
    private String tag;

    @ApiParam(value = "户口类型")
    private Integer regType;

    @ApiParam(value = "参保管理Id列表")
    private List<String> empSocInfoIdList;

    @ApiParam(value = "社保账号")
    private String socAccount;

    @ApiParam(value = "医保账号")
    private String meAccount;

    @ApiParam(value = "公积金账号")
    private String pfAccount;

    @ApiParam(value = "签约主体")
    private String contractSubject;

    @ApiParam(value = "姓名身份证号")
    private String nameAndIdCard;

    @ApiParam(value = "查询时间(甲方端小程序社保列表页查询参数)")
    private String date;

    @ApiParam(value = "社保名单/参保管理导出,表头信息")
    List<FieldItemVO> headInfo;

    @ApiParam(value = "员工Id列表")
    private List<String> empIdList;

    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public EmpSocInfoQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

